package WORKPLACE;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import TOOLS.SQLtool;

public class test008 {

	public static void main(String[] args)  {
		SQLtool sql=new SQLtool();
		String IPaddr="192.168.1.1";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			IPaddr=addr.getHostAddress();
		} catch (UnknownHostException e1) {
			;
		}
		sql.config(IPaddr, "AKS2019", "sa", "123456","test008");
		sql.config("192.168.0.39", "AKS2019", "sa", "abcd1234!","test008");
		try {
			JFrame j=new JFrame();
			j.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			j.setVisible(true);
			j.setLocation(-800, 0);
			sql.connect();
			
			String tableName="[dbo].[resource_pallet]";
			String sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			try {
				sql.Command(sqlStr);
			} catch (Exception e) {
				if(e.getMessage().equals("-11")) {
					;
				}else {
					throw e;
				}
			}
			sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
					"[resourcePalletIndex] int IDENTITY(1,1) NOT NULL UNIQUE,\r\n" + 
					"[palletID] varchar(100) NOT NULL ,\r\n" + 
					"[serialNumber] varchar(100) NOT NULL ,\r\n" + 
					"[lastTime] datetime DEFAULT GETDATE() \r\n" + 
					")";
			sql.Command(sqlStr);
			
			sql.close();
			j.dispose();
			System.exit(0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
